﻿Chenxin.UI.ShowListIntentMoney = Chenxin.extend(Chenxin.UI.PageCommon, {
    autoInitForm: false,
    actionUrl: '/service/logic/ShowListIntentMoney.ashx',
    createSearch: function() {
        return new Chenxin.UI.ShowListIntentMoneySearch({
            scope: this
        });
    },
    createGrid: function() {
        return new Chenxin.UI.JsonGrid({
            actionUrl: this.actionUrl + '?op=getlist',
            id: 'Letter_table',
            renderTo: 'Letter_table',
            hasCheckBox: false,
            modelId: 'BillId',
            pageSize: 50,
            height: 400,
            cellBorder: true,
            scope: this,
            columns: {
                IntentionCode: {
                    head: '意向书编号',
                    width: 180,
                    sortable: true,
                    sortField: 'a.IntentionCode',
                    style: 'text-align:left',
                    renderer: function(val, c, row) {
                        return '<a href="/page/LetterOfIntent_Mgr/IntentDetail.aspx?IntentionId=' + row.IntentionId + '" target="_blank">' + val + '</a>';
                    }
                },
                GetedCompany: {
                    head: '公司',
                    width: 120,
                    sortable: true,
                    style: 'text-align:left',
                    sortField: 'a.GetedCompanyId'
                },
                bussiness: {
                    style: 'text-align:left',
                    head: '商圈',
                    width: 120
                },
                GetedDepart: {
                    style: 'text-align:left',
                    head: '门店',
                    width: 100,
                    sortable: true,
                    sortField: 'a.GetedDepartId'
                },
                GetedEmployee: {
                    style: 'text-align:left',
                    head: '业务员',
                    width: 70,
                    sortable: true,
                    sortField: 'a.GetedDepartId'
                },
                HouseAddress: {
                    style: 'text-align:left',
                    head: '地址',
                    width: 200
                },
                AccountType: { style: 'text-align:left',
                    head: '账户类型',
                    width: 70,
                    sortable: true,
                    sortField: 'AccountType',
                    renderer: function(val, field, row) {
                        if (val == 10) {
                            return '公司账户';
                        }
                        else
                            return '授权账户';
                    }
                },
                BillCode: { style: 'text-align:left',
                    head: '收据号',
                    width: 150,
                    sortable: true,
                    sortField: 'a.BillCode',
                    renderer: function(val, c, row) {
                        return '<a href="/page/LetterOfIntent_Mgr/IntentMoneyDetail.aspx?BillId=' + row.BillId + '" target="_blank">' + val + '</a>';
                    }
                },
                Status: { style: 'text-align:left',
                    head: '状态',
                    width: 70,
                    sortable: true,
                    sortField: 'a.Status',
                    renderer: function(val, field, row) {
                        if (val == -1) {
                            return '作废';
                        }
                        else
                            return '正常';
                    }
                },
                CustomerName_Buy: { style: 'text-align:left',
                    head: '客户姓名',
                    width: 70,
                    sortable: true,
                    sortField: 'CustomerName_Buy'
                },
                CustomerName_Sale: { style: 'text-align:left',
                    head: '房东姓名',
                    width: 70,
                    sortable: true,
                    sortField: 'CustomerName_Sale'
                },
                GetedTime: { style: 'text-align:left',
                    head: '收/转时间',
                    width: 70,
                    sortable: true,
                    sortField: 'GetedTime'
                },
                FirstMoney: { style: 'text-align:left',
                    head: '首笔金额',
                    width: 100,
                    sortable: true,
                    sortField: 'FirstMoney'
                },
                TotalMoney: { style: 'text-align:left',
                    head: '总金额',
                    width: 100,
                    sortable: true,
                    sortField: 'TotalMoney'
                },
                GetedMoney: { style: 'text-align:left',
                    head: '收款金额',
                    width: 100,
                    sortable: true,
                    sortField: 'a.GetedMoney',
                    renderer: function(val, field, row) {
                        if (row.InOrOut != 1) {
                            return '';
                        }
                        else {
                            return val;
                        }
                    }
                },
                PayMoney: { style: 'text-align:left',
                    head: '转移金额',
                    width: 100,
                    sortable: true,
                    sortField: 'a.GetedMoney',
                    renderer: function(val, field, row) {
                        if (row.InOrOut != 0) {
                            return '';
                        }
                        else {
                            return row.GetedMoney;
                        }
                    }
                },
                PayTo: { style: 'text-align:left',
                    head: '转移去向',
                    width: 100,
                    sortable: true,
                    sortField: 'a.PayTo',
                    renderer: function(val, field, row) {
                        if (val == 10)
                            return '转定金';
                        else if (val == 20)
                            return '转房款';
                        else if (val == 30)
                            return '退还客户';
                        else if (val == 40)
                            return '转佣金';
                        else
                            return '';
                    }
                },
                IsConfirmed: { style: 'text-align:left',
                    head: '确认',
                    width: 50,
                    sortable: true,
                    sortField: 'a.IsConfirmed',
                    renderer: function(val, field, row) {
                        if (val == true) {
                            return '是';
                        }
                        else
                            return '否';
                    }
                },
                ConfirmEmployee: { style: 'text-align:left',
                    head: '确认人',
                    width: 70,
                    sortable: true,
                    sortField: 'a.ConfirmEmployee'
                },
                ConfirmDate: { style: 'text-align:left',
                    head: '确认时间',
                    width: 70,
                    sortable: true,
                    sortField: 'a.ConfirmDate'
                },
                IsReview: { style: 'text-align:left',
                    head: '复核',
                    width: 50,
                    sortable: true,
                    sortField: 'a.IsReview',
                    renderer: function(val, field, row) {
                        if (val == true) {
                            return '是';
                        }
                        else
                            return '否';
                    }
                },
                ReviewEmployee: { style: 'text-align:left',
                    head: '复核人',
                    width: 70,
                    sortable: true,
                    sortField: 'a.ReviewEmployee'
                },
                ReviewDate: { style: 'text-align:left',
                    head: '复核时间',
                    width: 70,
                    sortable: true,
                    sortField: 'a.ReviewDate'
                },
                bCustody: { style: 'text-align:left',
                    head: '代保管',
                    width: 50,
                    sortable: true,
                    sortField: 'a.bCustody',
                    renderer: function(val, field, row) {
                        if (val == '') {
                            return '';
                        }
                        else if (val == 10) {
                            return '是';
                        }
                        else
                            return '否';
                    }
                },
                Addtime: { style: 'text-align:left',
                    head: '建档时间',
                    width: 70,
                    sortable: true,
                    sortField: 'a.Addtime'
                },
                AddEmployee: { style: 'text-align:left',
                    head: '建档人',
                    width: 70,
                    sortable: true,
                    sortField: 'a.AddEmployee'
                }
            },
            rowRenderer: function(row, index, dl) {
                if (row.Status == -1) {
                    dl.css("background-color", "#CCCCCC");
                } else if (row.InOrOut == 0) {
                    dl.css("background-color", "#FFCCFF");
                } else {
                    dl.css("background-color", "#C9FED2");
                }
            }
        });
    },
    initEvent: function() {
        var _this = this;
        /*************************事件：起始日期得到焦点************************/
        $("#DateFr").focus(function() {
            WdatePicker({ dateFmt: 'yyyy-MM-dd', oncleared: function() { $(this).blur(); }, onpicked: function() { $(this).blur(); } })
        });
        /*************************事件：终止日期得到焦点************************/
        $("#DateTo").focus(function() {
            WdatePicker({ dateFmt: 'yyyy-MM-dd', oncleared: function() { $(this).blur(); }, onpicked: function() { $(this).blur(); } })
        });

        /*************************事件：列表行点击事件************************/
        $('.tr_letterlist').live('click', function() {
            $('.tr_letterlist,.selected_orgbgcolor').each(function() {
                $(this).removeClass('selected_orgbgcolor');
            });

            $(this).toggleClass('selected_orgbgcolor');
            if (!$('#tr-letter-info').length) {
                _this.currentId = this.id;
            } else {
                $('#tr-letter-info').remove();
                if (_this.currentId != this.id) {
                    _this.currentId = this.id;
                }
            }
        });
        /*************************事件：列表行鼠标滑过************************/
        $('.tr_letterlist').live('mouseover', function() {
            $(this).toggleClass('orgbgcolor');
        });
        /*************************事件：列表行鼠标离开************************/
        $('.tr_letterlist').live('mouseout', function() {
            $(this).toggleClass('orgbgcolor');
        });
        $('#keyword').defText({
            deftxt: '输入意向书/房源/单据编号'
        });

        /*************************事件：意向金详情************************/
        $("#amoneyinfo").click(function() {
            if (_this.currentId == null || _this.currentId == "") {
                alert("请先选择一条记录！");
                return;
            }
            window.open("/page/LetterOfIntent_Mgr/IntentMoneyDetail.aspx?BillId=" + _this.currentId);
        });
        /*************************事件：意向金作废************************/
        $("#amoneycancel").click(function() {
            if (_this.currentId == null || _this.currentId == "") {
                alert("请先选择一条记录！");
                return;
            }
            _this.moneycancel();
        });

        /*************************事件：意向金财务确认************************/
        $("#amoneycheck").click(function() {
            _this.del('moneycheck', '是否确认？');
        });
        /*************************事件：意向金反确认************************/
        $("#acheckcancel").click(function() {
            _this.del('checkcancel', '取消确认？');
        });
        /*************************事件：意向金复核************************/
        $("#acheckagain").click(function() {
            _this.del('checkagain', '是否复核？');
        });
        /*************************事件：意向金反复核************************/
        $("#acheckagaincancel").click(function() {
            _this.del('checkagaincancel', '取消复核？');
        });
        /*************************事件：意向金代保管************************/
        $("#amoneykeep").click(function() {
            _this.del('moneykeep', '是否确认代保管？');
        });
        $("#aprint").click(function() {
            _this.print();
        });
    },
    print: function() {
        var objFrm = this;
        if (!this.currentId) {
            alert('请先选择一条意向金记录！');
            return;
        };
        if (this.grid.getCurrentRecord().Status == "-1") {
            alert("此意向金已作废，不可打印");
            return false;
        };
        if (this.grid.getCurrentRecord().InOrOut == "1") {//收款单
            if (objFrm.printInForm == undefined) {
                objFrm.printInForm = new Chenxin.UI.PrintInMoneyForm({
                    scope: objFrm,
                    op: 'reprintview'
                });
            };
            objFrm.printInForm.reset();
            if (objFrm.printInForm.show('reprintview') == false) return;

            Chenxin.ajax({
                type: "get",
                dataType: "json",
                url: objFrm.printInForm.actionUrl,
                data: { op: 'getprintmodel', billId: this.grid.getCurrentRecord().BillId },
                onSuccess: function(data) {
                    objFrm.printInForm.fitData(data.model);
                }
            });
        } else {//付款单
            if (this.grid.getCurrentRecord().PayTo == 30) {//退还客户
                if (objFrm.printOutForm == undefined) {
                    objFrm.printOutForm = new Chenxin.UI.PrintOutToMoneyForm({
                        scope: objFrm,
                        op: 'reprintview'
                    });
                };
                objFrm.printOutForm.reset();
                if (objFrm.printOutForm.show('reprintview') == false) return;

                Chenxin.ajax({
                    type: "get",
                    dataType: "json",
                    url: objFrm.printOutForm.actionUrl,
                    data: { op: 'getprintmodel', billId: this.grid.getCurrentRecord().BillId },
                    onSuccess: function(data) {
                        objFrm.printOutForm.fitData(data.model);
                    }
                });
            } else {    //其他转向
                if (objFrm.printMoveForm == undefined) {
                    objFrm.printMoveForm = new Chenxin.UI.PrintOutMoveMoneyForm({
                        scope: objFrm,
                        op: 'reprintview'
                    });
                };
                objFrm.printMoveForm.reset();
                if (objFrm.printMoveForm.show('reprintview') == false) return;
                Chenxin.ajax({
                    type: "get",
                    dataType: "json",
                    url: objFrm.printMoveForm.actionUrl,
                    data: { op: 'getprintmodel', billId: this.grid.getCurrentRecord().BillId },
                    onSuccess: function(data) {
                        objFrm.printMoveForm.fitData(data.model);
                    }
                });
            };
        };
    },
    /**
    *作废
    */
    moneycancel: function() {
        var _this = this;
        if (!this.MoneyCancelForm) {
            this.MoneyCancelForm = new Chenxin.UI.MoneyCancel({
                scope: this,
                op: 'cancelmove',
                title: '作废单据',
                alwaysCheckPermit: true,
                afterGetFormJson: function(model) {
                    this.MoneyCancelForm.additionalParam.modelid = _this.currentId;
                    this.MoneyCancelForm.additionalParam.DeleteReason = model.DeleteReason;
                }
            });
        }
        if (this.MoneyCancelForm.show(this.MoneyCancelForm.op, { modelid: _this.currentId })) {
            Chenxin.Fn.getModel(_this.currentId, this.actionUrl, function(model) {
                this.fitData(model);
            }, this.MoneyCancelForm, 'getcancel');
        }
    },
    initComponent: function() {
        Chenxin.UI.ShowListIntentMoney.superclass.initComponent.call(this);
    }
});

/**
*意向金作废
*/
Chenxin.UI.MoneyCancel = Chenxin.extend(Chenxin.UI.FormCommon, {
    actionUrl: '/service/logic/ShowListIntentMoney.ashx',
    id: 'MoneyCancel',
    renderTo: 'divmoneycancel',
    winCls: '',
    jqmWidth: 650,
    defBBtn: true,
    createForm: function() {
        return Chenxin.FormCommon.MoneyCancel(this.id);
    },
    initEvent: function() {
        var _this = this;
        var thisid = '#' + this.id;
        _this.isclick = true;

        $(thisid + '_save').live('click', function() {
            if (_this.isclick) {
                _this.save();
            }
        });
        $(thisid + '_cancle').live('click', function() {
            _this.hide();
        });
    },
    initFormValidator: function() {
        //作废原因
        $("#DeleteReason").formValidator({
            validatorgroup: this.id,
            onshow: "请输入原因！",
            onfocus: "请输入原因！",
            oncorrect: " "
        }).inputValidator({
            min: 1,
            empty: {
                leftempty: false,
                rightempty: false,
                emptyerror: "原因不能为空！"
            },
            onerror: "原因不能为空！"
        });
    },
    saveSucc: function() {
        this.reloadGrid();
    },
    initComponent: function() {
        Chenxin.UI.MoneyCancel.superclass.initComponent.call(this);
    }
});

Chenxin.FormCommon.MoneyCancel = function(formID) {
    return '<table><tr style="line-height:40px;"><td style="margin-right: 5px;width:100px; text-align:right;"><span >意向书编号：</span></td><td><input type="text" name="IntentionCode" class="inputbox_n" readonly="true" style="width:180px;" /></td ></tr><tr style="line-height:40px;"><td style="margin-right: 5px;text-align:right;"><span >物件地址：</span></td><td><input type="text" class="inputbox_n" name="HouseAddress" readonly="true" style="width:180px;"/></td></tr><tr style="line-height:40px;"><td style="margin-right: 5px;text-align:right;"><span >开单编号：</span></td><td><input type="text" class="inputbox_n" name="BillCode" readonly="true" style="width:180px;"/></td ></tr><tr style="line-height:40px;"><td style="margin-right: 5px;text-align:right;"><span >开单金额：</span></td><td><input type="text" class="inputbox_n" name="GetedMoney" readonly="true" style="width:180px;"/></td></tr><tr style="line-height:40px;padding-top:10px;"><td  valign="top"  style="margin-right: 5px;text-align:right;"><span >作废原因：</span></td><td colspan="3"><div style="float:left;padding-bottom:10px;margin-top:5px;"><textarea id="DeleteReason" class="textarea_n"  name="DeleteReason" cols="55" rows="5"></textarea></div></td></tr><tr><td></td><td><div id="DeleteReasonTip" style="float: left; width: 70; height: 26px; line-height: 26px; margin-bottom:15px; text-align: left;" class="fl"></div></td></tr></table></html>';
};

/**
*查询面板
*/
Chenxin.UI.ShowListIntentMoneySearch = Chenxin.extend(Chenxin.UI.SearchCommon, {
    id: 'money_search',
    initEvent: function() {
        var _this = this;

        //查询按钮
        $('#btn_search').click(function() {
            _this.scope.reloadGrid("",0);
        });
    },
    createComboList: function() {
        //单据类型
        var cmbintenttype = new Chenxin.UI.Combo({
            containerId: '#divstatus',
            tbxWidth: 65,
            name: 'type',
            items: [{ txt: '全部', val: '1' }, { txt: '付款单据', val: '2' }, { txt: '转移单据', val: '3' }]
        });

        //状态
        var cmbstatus = new Chenxin.UI.Combo({
            containerId: '#divzt',
            tbxWidth: 65,
            name: 'Status',
            items: [{ txt: '正常', val: '1' }, { txt: '作废', val: '-1' }]
        });
        
        //账户类型
        var cmbtype = new Chenxin.UI.Combo({
            containerId: '#divtype',
            tbxWidth: 65,
            name: 'AccountType',
            items: [{ txt: '公司账户', val: '10' }, { txt: '授权账户', val: '20'}]
        });

        //财务确认
        var cmbIsConfirmed = new Chenxin.UI.Combo({
            containerId: '#divIsConfirmed',
            tbxWidth: 40,
            name: 'IsConfirmed',
            items: comboCommon.IsVirtual
        });

        //代保管
        var cmbbCustody = new Chenxin.UI.Combo({
            containerId: '#divbCustody',
            tbxWidth: 50,
            name: 'bCustody',
            items: [{ txt: '是', val: '10' }, { txt: '否', val: '0'}]
        });

        //意向金去向
        var cmbPayedTo = new Chenxin.UI.Combo({
            containerId: '#divPayedTo',
            tbxWidth: 65,
            name: 'PayedTo',
            items: [{ txt: '转定金', val: '10' }, { txt: '转房款', val: '20' }, {txt:'退还下家',val:'30'}]
        });

        //五级联Combo
        var combl = new Chenxin.UI.StructComboList({
            tbxWidth: 65
        });
        var structs = combl.comboList;
        structs.push(cmbstatus);
        structs.push(cmbtype);
        structs.push(cmbIsConfirmed);
        structs.push(cmbbCustody);
        structs.push(cmbPayedTo);
        structs.push(cmbintenttype);
        return structs;
    },
    initComponent: function() {
        Chenxin.UI.ShowListIntentMoneySearch.superclass.initComponent.call(this);
    }
});

getcity = true; //设置需要获取城市下拉框数据

$(document).ready(function() {
    var showlistintentmoney = new Chenxin.UI.ShowListIntentMoney();
});